<template>
  <div>
    <el-dialog v-if="isShow" :visible="isUpdateDialog" title="编辑学科" width="400px" @close="onClose">
      <el-form :model="form" :rules="rules">
        <el-form-item label="学科名称" prop="subjectName">
          <el-input v-model="form.subjectName" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <el-form>
        <el-form-item label="是否显示">
          <el-switch
              v-model="form.isFrontDisplay"
              :active-value="1"
              active-color="#13ce66"
              inactive-color="#ff4949"
              inactive-value="0"
          >
          </el-switch>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="onClose()">取 消</el-button>
        <el-button type="primary" @click="updateSubjectsForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import { updateSubjects } from '../../api/hmmm/subjects'

export default {
  name: 'subjects-update',
  props: {
    isUpdateDialog: {
      type: Boolean,
      required: true
    },
    form: {
      type: Object,
      required: true
    },
    isShow: {
      type: Boolean,
      required: true
    }
  },
  created () {
  },
  data () {
    return {
      // 表单校验规则
      rules: {
        subjectName: [
          { required: true, message: '请输入学科名称', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 关闭弹框重置
    onClose () {
      this.$emit('update:form', {})
      this.$emit('update:isShow', false)
      this.$emit('update:isUpdateDialog', false)
    },
    async updateSubjectsForm () {
      await updateSubjects(this.form)
      this.$emit('update:isUpdateDialog', false)
      this.$emit('loadSubjectsList')
      this.$message.success('修改成功')
      this.$emit('update:form', {})
      this.$emit('update:isShow', false)
    }
  }
}
</script>

<style scoped>

</style>
